#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QDebug>
#include <QImage>
#include <QPainter>
#include <QKeyEvent>
#include <QTimer>
#include "thread.h"
#include "keythread.h"
#include <QDateTime>
#include <QDir>
#include <QMutex>
#include <QMutexLocker>
#include <QMouseEvent>
#include <QEvent>

#include "common.h"
#include "tipwidget.h"
#include "server.h"

#define QT_USE_SPACE (100*1024*1024)

namespace Ui {
class MainWindow;
}

enum View_n
{
    VIEW_ONE                    ,
    VIEW_ONE_STATIC             ,
    VIEW_TWO                    ,
    VIEW_TWO_STATIC_FIRST       ,
    VIEW_TWO_STATIC_SECOND      ,
    VIEW_TWO_STATIC_SECOND_ONLY ,
    VIEW_FOUR                   ,
    VIEW_FOUR_STATIC_FIRST      ,
    VIEW_FOUR_STATIC_SECOND     ,
    VIEW_FOUR_STATIC_THIRD      ,
    VIEW_FOUR_STATIC_FOURTH     ,
    VIEW_FOUR_FREE_ONE          ,
    VIEW_FOUR_FREE_TWO          ,
    VIEW_FOUR_FREE_THREE        ,
    VIEW_MAX
};

enum Scale_n
{
    SCALE_0_4,
    SCALE_0_6,
    SCALE_0_8,
    SCALE_1_0,
    SCALE_1_2,
    SCALE_1_4,
    SCALE_1_6,
    SCALE_1_8,
    SCALE_2_0,
    SCALE_MAX
};

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    void mousePressEvent(QMouseEvent *)override;
    void mouseReleaseEvent(QMouseEvent *)override;

    QTimer timer;
    QMutex mutex;
    Thread *thread;
    View_n view = VIEW_ONE;
    Scale_n scale = SCALE_1_0;
    bool event(QEvent *e)override;
private:
    //Ui::MainWindow *ui;

    void paintEvent(QPaintEvent *)override;

    QImage img;
    QImage img_oneView_static;
    QImage img_twoView_static1;
    QImage img_twoView_static2;
    QImage img_fourView_static1;
    QImage img_fourView_static2;
    QImage img_fourView_static3;
    QImage img_fourView_static4;

    void saveImg(QImage img, QString path);
public slots:
    void image(uchar *);

    void KeyEvent(Key_t, int);

signals:
    void sigClose();
};

#endif // MAINWINDOW_H
